package com.un10.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.un10.entity.Paytable;
import com.un10.entity.User;
import com.un10.service.PaytableService;
import com.un10.util.Result;

@Controller
public class PaytableController {

	@Autowired
	PaytableService paytableService;

	@RequestMapping("/houtai/getAllPaytable")
	@ResponseBody
	public Object getpaytable(@RequestParam("page") int page, @RequestParam("limit") int limit,
			@RequestParam("payMethod") String payMethod) {

		List<Paytable> paytable = paytableService.findAllPaytable(page, limit, payMethod);

		if (payMethod == null || payMethod == "") {
			payMethod = null;
		}
		int count = paytableService.getCount();
		System.out.println(payMethod);
		com.un10.util.Result res = new com.un10.util.Result(0, "", count, paytable);
		return res;
	}

	@RequestMapping("/houtai/paytableadd")
	@ResponseBody
	public Object paytableadd(@RequestParam Map<String, Object> map) {

		System.out.println(map.get("payMethod"));
		int i = paytableService.findPaytableAdd(map);
		Result res = new Result(0, "", i, true);
		return res;
	}

	@RequestMapping("/houtai/updatepaytable")
	@ResponseBody
	public Object updatepaytable(@RequestParam Map<String, Object> map) {

		int i = paytableService.findPaytableUpdate(map);
		Result res = new Result(0, "", i, true);
		return res;
	}

	@RequestMapping("/houtai/paytabledelete")
	@ResponseBody
	public Object paytabledelete(@RequestParam("payID") Integer payID) {
		int i = paytableService.findPaytableDelete(payID);
		Result res = new Result(0, "", i, true);
		return res;
	}
}